<template>
  <div>
    <div :class="$style.logo">
      <div>
        <img :class="$style.img" src="@/icons/png/logo.png" />
      </div>
    </div>

    <el-menu
      :collapse="isCollapse"
      :collapse-transition="false"
      :default-active="active"
      active-text-color="#409eff"
      background-color="#304156"
      text-color="#bfcbd9"
      unique-opened
      @select="select"
    >
      <template v-for="(item, index) in navList">
        <el-submenu v-if="item.children" :key="index" :index="item.index">
          <template slot="title">
            <img v-if="item.icon" :class="$style.navIcon" :src="item.icon" />
            <i v-else class="el-icon-menu"></i>
            <span>{{ item.title }}</span>
          </template>
          <el-menu-item
            v-for="(Item, index) in item.children"
            :key="index"
            :index="Item.index"
          >
            {{ Item.title }}
          </el-menu-item>
        </el-submenu>

        <el-menu-item v-else :key="index" :index="item.index">
          <img v-if="item.icon" :class="$style.navIcon" :src="item.icon" />
          <i v-else class="el-icon-menu"></i>
          <span slot="title">{{ item.title }}</span>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  computed: {
    isCollapse() {
      return this.$store.state.isNavShrink;
    },
    active() {
      return this.$route.path;
    },
    navList() {
      return this.$store.getters.navList;
    },
  },

  methods: {
    select(index) {
      this.$router.push(index);
    },
  },
};
</script>

<style lang="scss" module>
.navIcon {
  width: 15px;
  height: 15px;
  margin-right: 20px;
}

.logo {
  margin: 30px 26% 10px 27%;
}

.img {
  width: 100%;
  height: 100%;
  border-radius: 5px;
}
</style>